	<?php $authedUser = $session->read('Auth.User');?>
	<?php
	$type = 'text';
	$senderName = $senderEmail = '';
	if($authedUser)
	{
		$senderName = $authedUser['username'];
		$senderEmail = $authedUser['email'];
		$type ='hidden';
	}
	?>
	<?php		
	echo $form->create('Invite',array('action'=>'inviteFriends/'.$listing_id,'id'=>'invite_form'));
	echo $form->input('Sender.name',array('label'=>'Your name','type'=>$type,'value'=>$senderName,'class'=>'required'));
	echo $form->input('Sender.email',array('class'=>'required email','label'=>'Your Email Address','type'=>$type,'value'=>$senderEmail));
	for($i = 0; $i <= 1; $i++)
	{
		$j = $i;
		$j++;
		if($j == 1)
		{
			$classRequired = 'required';
		}
		else
		{
			$classRequired = '';
		}
		$classEmail = 'email';
		echo $form->input('Invite.'.$i.'.name',array('label'=>sprintf(__("Friend #%s Name:"),$j),'class'=>$classRequired));
		echo $form->input('Invite.'.$i.'.email',array('label'=>sprintf(__("Friend #%s Email:"),$j),'class'=>$classRequired.' '.$classEmail));
	}?>
	
	<div id='add'></div>
	<?php echo $html->link(__('Add More Friend'),'#',array('onclick'=>'return addMoreField()','id'=>'add_link'));?>
	<?php
	if(!isset($this->data['Invite']['title']))
	{
		$this->data['Invite']['title'] = '';
	}
	if(!isset($this->data['Invite']['body']))
	{
		$this->data['Invite']['body'] = '';
	}	
	echo $form->end(array(__('Send Message'),'class'=>'valid'));
	?>

	<script src="<?php echo $html->url('/cms/js/jquery.template.js')?>" type='text/javascript'></script>
	<?php
	$this->addScript('<script type="text/javascript" src="'.$html->url('/cms/js/jquery.validate.min.js').'"></script>');?>

	<script type='text/javascript'>
	var fieldTemplate = '<div class="input text"><label for="Invite${i}Name"><?php echo sprintf(__("Friend #%s Name:"),'${j}')?></label><input name="data[Invite][${i}][name]" type="text" value="" id="Invite${i}Name" /></div><div class="input text"><label for="Invite${i}Email"><?php echo sprintf(__("Friend #%s Email:"),'${j}')?></label><input name="data[Invite][${i}][email]" type="text" value="" id="Invite${i}Email" /></div>';

	var tempObj = new templateCount(<?php echo $i?>);
	function templateCount(index)
	{
		this.count = index;
	}
	var temp = $.template(fieldTemplate);
	function addMoreField()
	{
		if(tempObj.count==9)
		{
			$('#add_link').fadeOut('slow');
		}
		$('#add').append(temp,{'i':tempObj.count,'j':tempObj.count+1});
		tempObj.count++;
		return false ;
	}
	$('.valid').click(function()
	{
		if($('#invite_form').valid()==false)
		{
			return;
		}
	});
	</script>